home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <setjmp.h>
- #include "lint.h"
- #include "interpret.h"
- #include "config.h"
- #include "object.h"
- #include "lex.h"
- #include "rc.h"
-
- #include <quickdraw.h>
- #include <memory.h>
- #include <cursorctl.h>
- #include <mac.h>
-
- void InitConsole();
-
- int slow_shut_down_to_do;
- int d_flag = 0; /* Run with debug */
- int t_flag = 0; /* Disable heart beat and reset */
- int e_flag = 0; /* Load empty, without castles. */
- int comp_flag = 0; /* Trace compilations */
- long time_to_swap; /* marion - invocation parameter */
-
- #ifdef YYDEBUG
- extern int yydebug;
- #endif
-
- int port_number;
- char *reserved_area; /* reserved for malloc() */
- struct svalue const0, const1;
-
- double consts[5];
-
- extern jmp_buf error_recovery_context;
- extern int error_recovery_context_exists;
-
- extern struct object *master_ob;
-
- struct wiz_list *back_bone_uid;
-
- static void start_ip_demon();
-
- int lpmain(void)
- {
- int i;
- char *p;
- extern int num_player;
- struct svalue simulf;
- extern FILE *swap_file;
- extern int current_time;
- extern int new_name_count;
- extern void clear_defines();
- extern void init_compiler(void);
- extern void flush_instr_cache(void);
- extern int slow_shut_down_to_do;
- extern int game_is_being_shut_down;
- extern struct program *prog;
- extern struct object *obj_list;
- extern struct object *previous_ob;
- extern struct object *command_giver;
- extern struct program *current_prog;
- extern struct object *current_object;
- extern struct object *obj_list_destruct;
- extern struct object *current_interactive;
- extern struct interactive **all_players;
-
-
- #ifndef COMPAT_MODE
- struct svalue *ret;
- #endif
-
- prog = NULL;
- num_player = 0;
- master_ob = NULL;
- obj_list = NULL;
- swap_file = NULL;
- previous_ob = NULL;
- new_name_count = 0;
- current_prog = NULL;
- current_object = NULL;
- obj_list_destruct = NULL;
- current_interactive = NULL;
- game_is_being_shut_down = 0;
- slow_shut_down_to_do = 0;
- command_giver = 0;
- for (i = 0; i < MAX_PLAYERS; i++)
- all_players[i] = NULL;
-
- flush_instr_cache();
- clear_defines();
- init_otable();
- init_strings();
- init_compiler();
-
- InitConsole();
- printf("LPC Interpreter 3.1.2+.\nCompiled on ");
- printf(__DATE__);
- printf(" ");
- printf(__TIME__);
- printf(".\n");
- fflush(stdout);
- InitCursorCtl(NULL);
-
- const0.type = T_NUMBER; const0.u.number = 0;
- const1.type = T_NUMBER; const1.u.number = 1;
- /*
- * Check that the definition of EXTRACT_UCHAR() is correct.
- */
- p = (char *)&i;
- *p = -10;
- if (EXTRACT_UCHAR(p) != 0x100 - 10) {
- fprintf(stderr, "Bad definition of EXTRACT_UCHAR() in config.h.\n");
- LPExit(1);
- }
- // Initialize randomizer
- qd.randSeed = TickCount();
-
- init_num_args();
- reset_machine(1);
-
- current_time = get_current_time();;
- if (RESERVED_SIZE > 0)
- reserved_area = xalloc(RESERVED_SIZE);
- for (i=0; i < sizeof consts / sizeof consts[0]; i++)
- consts[i] = exp(- i / 900.0);
-
- if (setjmp(error_recovery_context)) {
- clear_state();
- add_message("Anomaly in the fabric of world space.\n");
- } else {
- error_recovery_context_exists = 1;
- simulf.type = T_STRING;
- simulf.string_type = STRING_CONSTANT;
- simulf.u.string = SIMUL_EFUN;
- get_simul_efun(&simulf);
- master_ob = load_object(MASTER_OBJECT,0, 0);
- }
- error_recovery_context_exists = 0;
- if (master_ob == 0) {
- fprintf(stderr, "The file %s must be loadable.\n",MASTER_OBJECT);
- LPExit(1);
- }
- /*
- * Make sure master_ob is never made a dangling pointer.
- * Look at apply_master_ob() for more details.
- */
- add_ref(master_ob, "main");
- #ifndef COMPAT_MODE
- ret = apply_master_ob("get_root_uid", 0);
- if (ret == 0 || ret->type != T_STRING) {
- fprintf(stderr, "get_root_uid() in %s does not work\n", MASTER_OBJECT);
- LPExit(1);
- }
- master_ob->user = add_name(ret->u.string);
- master_ob->eff_user = master_ob->user;
- ret = apply_master_ob("get_bb_uid", 0);
- if (ret == 0 || ret->type != T_STRING) {
- fprintf(stderr, "get_bb_uid() in %s does not work\n", MASTER_OBJECT);
- LPExit(1);
- }
- back_bone_uid = add_name(ret->u.string);
- #endif
- if (game_is_being_shut_down)
- LPExit(1);
- load_wiz_file();
- set_inc_list(apply_master_ob("define_include_dirs", 0));
- #ifdef COMPAT_MODE
- load_first_objects();
- (void)apply_master_ob("epilog", 0);
- #else
- preload_objects(e_flag);
- #endif
- backend();
-
- return 0;
- }
-
- char *string_copy(str)
- char *str;
- {
- char *p;
-
- p = xalloc(strlen(str)+1);
- (void)strcpy(p, str);
- return p;
- }
-
- /*VARARGS1*/
- void debug_message(a, b, c, d, e, f, g, h, i, j)
- char *a;
- int b, c, d, e, f, g, h, i, j;
- {
- fprintf(stderr, a, b, c, d, e, f, g, h, i, j);
- fflush(stderr);
- }
-
- void debug_message_svalue(v)
- struct svalue *v;
- {
- if (v == 0) {
- debug_message("<NULL>");
- return;
- }
- switch(v->type) {
- case T_NUMBER:
- debug_message("%d", v->u.number);
- return;
- case T_STRING:
- debug_message("\"%s\"", v->u.string);
- return;
- case T_OBJECT:
- debug_message("OBJ(%s)", v->u.ob->name);
- return;
- case T_LVALUE:
- debug_message("Pointer to ");
- debug_message_svalue(v->u.lvalue);
- return;
- default:
- debug_message("<INVALID>\n");
- return;
- }
- }
-
- #ifdef malloc
- #undef malloc
- #endif
-
- void xfree(char *p)
- {
- DisposPtr(p);
- }
-
- char *xalloc(int size)
- {
- char *p;
- extern void LPApplicZone(void);
- extern void LPRuntimeZone(void);
-
- LPRuntimeZone();
- p = NewPtr(size);
- LPApplicZone();
- if (p == 0) {
- fprintf(stderr, "Totally out of MEMORY.\n");
- fflush(stderr);
- (void)dump_trace(0);
- LPExit(2);
- }
- return p;
- }
-
- char *xrealloc(char *p, unsigned int size)
- {
- char *p2;
- extern void LPApplicZone(void);
- extern void LPRuntimeZone(void);
-
- if (p != NULL) {
- SetPtrSize(p, size);
- if (MemError() != noErr) {
- p2 = xalloc(size);
- memcpy(p2, p, GetPtrSize(p));
- xfree(p);
- p = p2;
- }
- } else {
- p = xalloc(size);
- }
- return p;
- }
-